package com.office.system.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.office.common.annotation.Log;
import com.office.common.core.controller.BaseController;
import com.office.common.core.domain.AjaxResult;
import com.office.common.enums.BusinessType;
import com.office.system.domain.SysRequest;
import com.office.system.service.ISysRequestService;
import com.office.common.utils.poi.ExcelUtil;
import com.office.common.core.page.TableDataInfo;

/**
 * 报修管理Controller
 * 
 * @author ruoyi
 * @date 2024-07-23
 */
@RestController
@RequestMapping("/system/request")
public class SysRequestController extends BaseController
{
    @Autowired
    private ISysRequestService sysRequestService;

    /**
     * 查询报修管理列表
     */
    @PreAuthorize("@ss.hasPermi('system:request:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysRequest sysRequest)
    {
        startPage();
        List<SysRequest> list = sysRequestService.selectSysRequestList(sysRequest);
        return getDataTable(list);
    }

    /**
     * 导出报修管理列表
     */
    @PreAuthorize("@ss.hasPermi('system:request:export')")
    @Log(title = "报修管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysRequest sysRequest)
    {
        List<SysRequest> list = sysRequestService.selectSysRequestList(sysRequest);
        ExcelUtil<SysRequest> util = new ExcelUtil<SysRequest>(SysRequest.class);
        util.exportExcel(response, list, "报修管理数据");
    }

    /**
     * 获取报修管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:request:query')")
    @GetMapping(value = "/{requestId}")
    public AjaxResult getInfo(@PathVariable("requestId") Long requestId)
    {
        return success(sysRequestService.selectSysRequestByRequestId(requestId));
    }

    /**
     * 新增报修管理
     */
    @PreAuthorize("@ss.hasPermi('system:request:add')")
    @Log(title = "报修管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysRequest sysRequest)
    {
        return toAjax(sysRequestService.insertSysRequest(sysRequest));
    }

    /**
     * 修改报修管理
     */
    @PreAuthorize("@ss.hasPermi('system:request:edit')")
    @Log(title = "报修管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysRequest sysRequest)
    {
        return toAjax(sysRequestService.updateSysRequest(sysRequest));
    }

    /**
     * 删除报修管理
     */
    @PreAuthorize("@ss.hasPermi('system:request:remove')")
    @Log(title = "报修管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{requestIds}")
    public AjaxResult remove(@PathVariable Long[] requestIds)
    {
        return toAjax(sysRequestService.deleteSysRequestByRequestIds(requestIds));
    }
}
